/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
 */
package td.domain;

// Using ArrayLists directly because of GWT
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import td.domain.util.StatisticalComparison;

import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Ignore;

/**
 * A thought that always belongs to only one topic (to keep thoughts strait
 * forward and simple). It can, however, reference any other thought across any
 * topic.
 * 
 * @author Artem Shamsutdinov
 * 
 */
@Entity
public class Thought extends Statistical {

	private static final long serialVersionUID = 645869747557044287L;

	public static StatisticalComparison currentComparisonType = StatisticalComparison.NUMBER_OF_THOUGHT_READS;

	private String text = "";

	// Any kind of an update (new thought or version, publishing of any version,
	// update of a version
	private Date lastUpdatedDate;

	private Date publishedDate;

	private Date lastPublishedOlderVersionDate;

	// FIXME: figure out how to add this to GWT
	// @Index(NotInListsCheck.class)
	private Long thinkerId;

	@Ignore
	private Thinker thinker;

	@Ignore
	private HashMap<Long, TagThought> appliedTags;

	@Ignore
	private ArrayList<Thought> referencedThoughts;

	@Ignore
	private ArrayList<Thought> referencingThoughts;

	boolean published = false;

	Integer highestSequence;

	Integer highestPublishedSequence = 0;

	// FIXME: add this back in and figure out how to deal with Ref in GWT
	// @Load(GetPublishedVersionIds.class)
	// private Ref<IdCache> recentPublishedVersionIds;
	//
	// @Load(GetUnpublishedVersionIds.class)
	// private Ref<IdCache> recentUnpublishedVersionIds;

	// @Load(GetThoughtsTags.class)
	// private Ref<Map<Long, Long>> mostAppliedTags;

	// FIXME: replace this with Objectify (above)
	@Ignore
	HashMap<Long, Long> mostAppliedTags = new HashMap<Long, Long>();

	@Ignore
	public Topic topic;

	public Thought() {
		super();
	}

	public Thought(String title, String synposis, String text, Long thinkerId) {
		super();
		this.name = title;
		this.description = synposis;
		this.text = text;
		this.thinkerId = thinkerId;
	}

	public String getTitle() {
		return name;
	}

	public void setTitle(String title) {
		this.name = title;
	}

	public String getSynopsis() {
		return description;
	}

	public void setSynopsis(String synopsis) {
		this.description = synopsis;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Thinker getThinker() {
		return thinker;
	}

	public void setThinker(Thinker thinker) {
		this.thinker = thinker;
	}

	public Date getLastUpdatedDate() {
		return lastUpdatedDate;
	}

	public void setLastUpdatedDate(Date lastUpdatedDate) {
		this.lastUpdatedDate = lastUpdatedDate;
	}

	public Date getPublishedDate() {
		return publishedDate;
	}

	public void setPublishedDate(Date publishedDate) {
		this.publishedDate = publishedDate;
	}

	public Date getLastPublishedOlderVersionDate() {
		return lastPublishedOlderVersionDate;
	}

	public void setLastPublishedOlderVersionDate(
			Date lastPublishedOlderVersionDate) {
		this.lastPublishedOlderVersionDate = lastPublishedOlderVersionDate;
	}

	public Long getThinkerId() {
		return thinkerId;
	}

	public void setThinkerId(Long thinkerId) {
		this.thinkerId = thinkerId;
	}

	public HashMap<Long, Long> getMostAppliedTags() {
		return mostAppliedTags;
	}

	public void setMostAppliedTags(HashMap<Long, Long> mostAppliedTags) {
		this.mostAppliedTags = mostAppliedTags;
	}

	public boolean isPublished() {
		return published;
	}

	public void setPublished(boolean published) {
		this.published = published;
	}

	public Integer getHighestSequence() {
		return highestSequence;
	}

	public void setHighestSequence(Integer highestSequence) {
		this.highestSequence = highestSequence;
	}

	public Integer getHighestPublishedSequence() {
		return highestPublishedSequence;
	}

	/**
	 * "Highest" because I'm still considering allowing to publish NEW versions
	 * of a thought AFTER the initial publishing, OR publishing OLD versions
	 * before the newest is published.
	 * 
	 * @param highestPublishedSequence
	 */
	public void setHighestPublishedSequence(Integer highestPublishedSequence) {
		this.highestPublishedSequence = highestPublishedSequence;
	}

	public HashMap<Long, TagThought> getAppliedTags() {
		return appliedTags;
	}

	public void setAppliedTags(HashMap<Long, TagThought> appliedTags) {
		this.appliedTags = appliedTags;
	}

	public ArrayList<Thought> getReferencedThoughts() {
		return referencedThoughts;
	}

	public void setReferencedThoughts(ArrayList<Thought> referencedThoughts) {
		this.referencedThoughts = referencedThoughts;
	}

	public ArrayList<Thought> getReferencingThoughts() {
		return referencingThoughts;
	}

	public void setReferencingThoughts(ArrayList<Thought> referencingThoughts) {
		this.referencingThoughts = referencingThoughts;
	}

	public Topic getTopic() {
		return topic;
	}

	public void setTopic(Topic topic) {
		this.topic = topic;
	}

	/* (non-Javadoc)
	 * @see td.domain.Statistical#getComparisonType()
	 */
	@Override
	public StatisticalComparison getComparisonType() {
		return currentComparisonType;
	}

	// public Ref<IdCache> getRecentPublishedVersionIds() {
	// return recentPublishedVersionIds;
	// }
	//
	// public void setRecentPublishedVersionIds(
	// Ref<IdCache> recentPublishedVersionIds) {
	// this.recentPublishedVersionIds = recentPublishedVersionIds;
	// }
	//
	// public Ref<IdCache> getRecentUnpublishedVersionIds() {
	// return recentUnpublishedVersionIds;
	// }
	//
	// public void setRecentUnpublishedVersionIds(
	// Ref<IdCache> recentUnpublishedVersionIds) {
	// this.recentUnpublishedVersionIds = recentUnpublishedVersionIds;
	// }

}
